# permission.py  权限表

# 权限表结构定义
# CREATE TABLE permissions (
#     id INT PRIMARY KEY AUTO_INCREMENT,  # 主键ID，自动递增
#     name VARCHAR(50) UNIQUE NOT NULL,  # 权限名称(唯一且必填)，如：create_data, edit_own_data等
#     description VARCHAR(200)  # 权限描述信息(可选)
# );

# 管理员权限关联表结构定义
# CREATE TABLE admin_permissions (
#     admin_id INT,  # 管理员用户ID
#     permission_id INT,  # 权限ID
#     FOREIGN KEY (admin_id) REFERENCES admin_users(id),  # 外键关联admin_users表
#     FOREIGN KEY (permission_id) REFERENCES permissions(id),  # 外键关联permissions表
#     PRIMARY KEY (admin_id, permission_id)  # 联合主键，确保每个管理员+权限组合唯一
# );

from exts import db
from .user import AdminUser

class Permission(db.Model):
    """权限数据模型"""
    __tablename__ = 'permissions'
    
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(50), unique=True, nullable=False)
    description = db.Column(db.String(200))
    
 
    def __repr__(self):
        return f'<Permission {self.name}>'

class AdminPermission(db.Model):
    """管理员权限关联模型"""
    __tablename__ = 'admin_permissions'
    
    admin_id = db.Column(db.Integer, db.ForeignKey('admin_users.id'), primary_key=True)
    # 管理员用户ID
    permission_id = db.Column(db.Integer, db.ForeignKey('permissions.id'), primary_key=True)
    # 权限ID
    
    
    def __repr__(self):
        return f'<AdminPermission admin:{self.admin_id} permission:{self.permission_id}>'


